import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:weui/button/index.dart';
import 'package:weui/form/index.dart';
import 'package:weui/input/index.dart';
import 'package:weui/weui.dart';
import 'package:yueyin/utils/yue_bar.dart';

class RegisterView extends StatefulWidget {
  const RegisterView({Key? key}) : super(key: key);

  @override
  _RegisterViewState createState() => _RegisterViewState();
}

class _RegisterViewState extends State<RegisterView> {
  late var _user = TextEditingController();
  late var _phone = TextEditingController();
  late var _code = TextEditingController();
  late var _password = TextEditingController();
  late var _name = TextEditingController();
  late var _birth = TextEditingController();

  late WeForm _form = WeForm(
    children: [
      WeInput(
        label: '登录账户',
        hintText: '请输入用户名',
        clearable: true,
        textInputAction: TextInputAction.next,
      ),
      WeInput(
        label: '手机号码',
        hintText: '请输入手机号码',
        type: TextInputType.phone,
        footer: WeButton(
          '获取验证码',
          theme: WeButtonType.primary,
          size: WeButtonSize.mini,
        ),
      ),
      WeInput(
        label: '验证码',
        hintText: '请输入获取到的验证码',
        textInputAction: TextInputAction.next,
      ),
      WeInput(
        label: '登录密码',
        hintText: '请输入登录密码',
        textInputAction: TextInputAction.next,
        obscureText: true,
      ),
      WeInput(
        label: '中文姓名',
        hintText: '请输入中文姓名',
        textInputAction: TextInputAction.next,
        footer: Row(
          children: <Widget>[
            WeSwitch(
              size: 20,
            ),
            SizedBox(width: 8),
            Text('男')
          ],
        ),
      ),
      WeCell(
        label: '畜生日期',
        content: '',
        onClick: () async {
          DatePicker.showDatePicker(context,
              showTitleActions: true,
              minTime: DateTime(2018, 3, 6),
              maxTime: DateTime(2022, 8, 9), onChanged: (date) {
                print('changed to => $date');
              }, onConfirm: (date) {
                print('confirm date => $date');
              }, currentTime: DateTime.now(), locale: LocaleType.zh);
        },
        footer: Row(
          children: <Widget>[
            WeSwitch(
              size: 20,
            ),
            SizedBox(width: 8),
            Text('阴历')
          ],
        ),
      ),
      Padding(
        padding: EdgeInsets.all(10),
        child: WeButton('注册', theme: WeButtonType.warn,),
      ),
    ],
  );

  @override
  void dispose() {
    super.dispose();
    _user.dispose();
    _phone.dispose();
    _code.dispose();
    _password.dispose();
    _name.dispose();
    _birth.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: bar('注册'),
      body: SingleChildScrollView(
        child: ClipRRect(
          child: Padding(
            padding: EdgeInsets.all(10),
            child: _form,
          ),
        ),
      ),
    );
  }
}
